package com.kashow.base;

import com.kashow.base.rx.RxManager;

import rx.Subscription;

/**
 * Created by yybs on 17/3/15.
 */

public class RxPresenter<T extends BaseView> implements BasePresenter<T> {
    protected T mView;
    protected RxManager mRxManager;

    @Override
    public void attachView(T view) {
        this.mView = view;
    }


    protected void unSubscribe(Object tag,Subscription subscription) {
        if (mRxManager != null) {
           mRxManager.removeSubscription(tag,subscription);
        }
    }

    protected void clear() {
        if (mRxManager != null) {
            mRxManager.removeSubscriptions(this);
        }
    }


    protected void addSubscrebe(Subscription subscription) {
        if (mRxManager == null) {
            mRxManager.addSubscription(this,subscription);
        }

    }


    @Override
    public void detachView() {
        this.mView = null;
        clear();
    }
}
